<?php
/**
 * 报价表
 * Created by PhpStorm.
 * User: sunku
 * Date: 2017/12/22
 * Time: 14:11
 */

namespace Resource\Service;
use Think\Model;

class QuotedService extends Model
{
    protected $trueTableName = 'wz_quoted';
    /**
     * @param $params
     * @return array|bool
     */
    public function addQuoted($params) {
        $params['status'] = 1;
        $params['create_time'] = time();
        $params['update_time'] = time();
        $id = D('Resource/Quoted')->addQuoted($params);
        if($id) {
            return $id;
        } else {
            return false;
        }
    }

    /**
     * @param $params
     * @param string $fields
     * @return mixed
     */
    public function getQuotedInfo($params, $fields='') {
        $dataInfo = D('Resource/Quoted')->getQuotedInfo($params,$fields);
        return $dataInfo;
    }

    /**
     * @param $params
     * @return array
     */
    public function searchQuotedList($params) {
        $page = 1;
        $page_size = 15;
        isset($params['page']) && $page = $params['page'];
        isset($params['page_size']) && $page_size = $params['page_size'];

        $data = [];
        isset($params['resource']) && $data['resource'] = ['like',"%{$params['resource']}%"];
        isset($params['platform']) && $data['platform'] = ['like',"%{$params['platform']}%"];
        isset($params['put_target']) && $data['put_target'] = ['like',"%{$params['put_target']}%"];

        //查询总数
        $total = D('Resource/Quoted')->getQuotedCount($data);

        //计算总页数
        $total_page = ceil($total / $page_size);
        if($page < 1) {
            $page = 1;
        }
        if($page > $total_page) {
            $page = $total_page;
        }

        //查询列表
        $dataList = D('Resource/Quoted')->getQuotedList($data, $page, $page_size);

        $result = [];
        $result['page'] = $page;
        $result['page_size'] = $page_size;
        $result['total'] = $total;
        $result['total_page'] = $total_page;
        $result['quotedList'] = $dataList;
        return $result;
    }

    /**
     * @param $params
     * @return mixed
     */
    public function updateQuotedInfo($params) {
        return D('Resource/Quoted')->updateQuotedInfo($params);
    }

    /**
     * @param $params
     * @return mixed
     */
    public function getAllQuotedList($params){
        $dataInfo = D('Resource/Quoted')->getAllQuotedList($params);
        return $dataInfo;
    }

    /**
     * @param $params
     * @return bool
     */
    public function deleteQuoted($params) {
        $result = D('Resource/Quoted')->deleteQuoted($params);
        if($result!=false) {
            return true;
        } else {
            return false;
        }
    }
}